<?php
namespace Backoffice\Form;

use Zend\Form\Fieldset;

class ProduitFieldset extends Fieldset
{
    public function init()
    {
        $em = $this->getFormFactory()->getFormElementManager()->getServiceLocator()->get('doctrine.entitymanager.orm_default');
        $this->setHydrator(new \DoctrineModule\Stdlib\Hydrator\DoctrineObject($em, 'Backoffice\Model\Entity\Produit'));
        
        $this->add(array(
            'type' => 'text',
            'name' => 'libelle',
            'options' => array('label' => 'Libelle :'),
            'attributes' => array(
                'class' => 'form-control',
            ),
        ));
        
        $this->add(array(
            'type' => 'textarea',
            'name' => 'description',
            'options' => array('label' => 'Description :'),
            'attributes' => array(
                'rows' => 4,
                'cols' => 100,
                'class' => 'form-control',
            ),
        ));
        
        $this->add(array(
            'type' => 'text',
            'name' => 'taille',
            'options' => array('label' => 'Taille :'),
            'attributes' => array(
                'class' => 'form-control',
            ),
        ));
        
        $this->add(array(
            'type' => 'text',
            'name' => 'prix',
            'options' => array('label' => 'Prix :'),
            'attributes' => array(
                'class' => 'form-control',
            ),
        ));
        
        $this->add(array(
            'type' => 'DoctrineModule\Form\Element\ObjectSelect',
            'name' => 'categorie',
            'options' => array(
                'label' => 'Catégorie :',
                'object_manager' => $em,
                'target_class' => 'Backoffice\Model\Entity\Categorie',
                'property' => 'libelle',
                'is_method' => true,
                'find_method' => array(
                    'name' => 'findBy',
                    'params' => array(
                        'criteria' => array(),
                    ),
                ),
            ),
        ));
        
        $this->add(array(
            'type' => 'DoctrineModule\Form\Element\ObjectSelect',
            'name' => 'etat',
            'options' => array(
                'label' => 'Etat :',
                'object_manager' => $em,
                'target_class' => 'Backoffice\Model\Entity\Etat',
                'property' => 'libelle',
                'is_method' => true,
                'find_method' => array(
                    'name' => 'findBy',
                    'params' => array(
                        'criteria' => array(),
                    ),
                ),
            ),
        ));
        
        $this->add(array(
            'type' => 'submit',
            'name' => 'submit',
            'options' => array('label' => 'Valider'),
            'attributes' => array('class' => 'btn btn-success'),
        ));
    }
}
